<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta content="telephone=no" name="format-detection" />
    <!-- 留作将来统一添加 -->
    <TEMPLATE>${TEMPLATE}</TEMPLATE>
    <title>模板html</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../../css/aui.css" />
    <link rel="stylesheet" type="text/css" href="../../css/index.css">
    <link rel="stylesheet" type="text/css" href="../../css/data-flex.min.css">
    <style type="text/css">
        body {
            background: rgba(90, 194, 255, 1);
        }

        .vueApp {
            padding-bottom: 10px;
        }

        .container {
            padding: 0 15px;
            margin: 15px;
            background: rgba(255, 255, 255, 1);
            box-shadow: 0px 4px 10px 0px rgba(0, 135, 214, 0.37);
            border-radius: 10px;
        }

        .head .title {
            font-size: 15px;
            font-weight: 400;
            color: rgb(102, 87, 87);
            margin-top: 10px;
            margin-bottom: 10px;
        }

        .main {
            flex-wrap: wrap;
            margin-right: -10px;
            margin-bottom: 10px;
        }

        .main .item {
            box-sizing: border-box;
            width: 33.3%;
            min-width: 33.3%;
            padding-right: 10px;
            padding-bottom: 10px;
        }

        .main .item .select {
            width: 100%;
            height:50px;
            background:rgba(245,245,245,1);
            border-radius:8px;
            font-size:18px;
            font-weight:500;
            color:rgba(231,109,0,1);
        }

        .main .item .active {
            background:rgba(253,155,67,1);
            color:rgba(255,255,255,1);
        } 

        .row {
            height: 50px;
        }

        .img {
            width: 30px;
            min-width: 30px;
            height: 30px;
            margin-right: 15px;
        }

        .name {
            font-size: 14px;
            font-weight: 400;
            color: rgba(36, 42, 51, 1);
        }

        .radio {
            width: 22px;
            height: 22px;
            min-width: 22px;
            -webkit-appearance: none;
            background: url("../../image/ui/radio.png");
            background-size: 100% 100%;
        }

        .radio:checked {
            background: url("../../image/ui/checked.png");
            background-size: 100% 100%;
        }

        .btn {
            width: 210px;
            height: 46px;
            background: url("../../image/ui/btn.png");
            background-size: 100% 100%;
            margin: 45px auto 0 auto;
            font-size: 18px;
            font-weight: 600;
            color: #7C4500;
            line-height: 42px;
            text-align: center;
            box-shadow: 0px 5px 7px 0px rgba(11, 126, 193, 0.53);
            border-radius: 22px;
        }

        .bor {
            height: 1px;
            background: rgb(212, 212, 212);
            transform: translateY(0.5);
        }
    </style>
</head>

<body>
    <div class="vueApp" v-cloak>
        <div class="container">
            <div class="head" data-flex="cross:center">
                <div style="width: 100%;">
                    <div class="title">
                        请选择充值金额
                    </div>
                    <div class="main" data-flex="cross:center">
                        <div class="item" v-for='item,index in moneyList' @click="setValue(item,index)">
                            <div :class="bindClass(1,index)" data-flex="main:center cross:center">¥{{ item.price }}</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div v-if="!isApplePay" class="container">
            <div class="row" data-flex="cross:center">
                <div class="img">
                    <img src="../../image/ui/wechat.png" alt="">
                </div>
                <div class="name" data-flex-box="1">
                    微信支付
                </div>
                <input class="radio" v-model="pay" value="1" type="radio" name="pay">
            </div>
            <div class="bor"></div>
            <div class="row" data-flex="cross:center">
                <div class="img">
                    <img src="../../image/ui/alipay.png" alt="">
                </div>
                <div class="name" data-flex-box="1">
                    支付宝支付
                </div>
                <input class="radio" v-model="pay" value="2" type="radio" name="pay">
            </div>
        </div>
        <div class="btn" @click="submitFn()">
            支付
        </div>
    </div>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/service/service-tool.js"></script>
<script type="text/javascript" src="../../script/service/service-app.js"></script>
<script type="text/javascript" src="../../script/service/service-user.js"></script>
<script type="text/javascript" src="../../script/service/service-logic.js"></script>
<script type="text/javascript" src="../../script/service/service-pay.js"></script>
<script type="text/javascript" src="../../script/jquery.min.js"></script>
<script type="text/javascript" src="../../script/vue.min.js"></script>
<script type="text/javascript">
    // html 的引号一律为双引号(""),js 为单引号('')
    var USER, $S, vm, pageParam = {};
    var isPay = false, retUrl = '', orderNo = '';
    apiready = function () {
        $S = SERVICE();
        USER = USER();
        console.log(JSON.stringify(api.pageParam) + '=====pageParam');
        pageParam = api.pageParam;
        fnInit();
    };
    // 初始化
    function fnInit() {
        vm = new Vue({
            el: '.vueApp',
            data: {
                isApplePay: false,
                count: '',
                pay: '1',
                active: -1,
                moneyList: []
            },
            methods: {
                setValue: function(item, index) {
                    this.active = index;
                    this.count = item.price;
                },
                bindClass: function(num, index) {
                    switch(num) {
                        case 1:
                            return this.active === index ? 'select active' : 'select';
                            break;
                        default:
                        console.error('请检查 bindClass 函数');
                    }
                }
            }
        });
        fnIsApplePay();
        findRechargeList();
    }

    function fnIsApplePay() {
        var apple_btn = api.systemType;
        var version = api.systemVersion.split('.')[0];
        // ios9.2以上才支持Apple Pay
        if (apple_btn == 'ios' && version >= 9) {
            vm.isApplePay = true;
            vm.pay = '3';
        }
    }

    function findRechargeList() {
        var params = {
            type: vm.isApplePay ? 1 : 2
        };
        var url = 'my/findRechargeList';
        var callback = function(data) {
            vm.moneyList = data.listData;
        };
        POST(url, params, callback);
    }

    // 支付
    function submitFn() {
        if (vm.count !== '' && (vm.pay !== '' || vm.systemType == 'ios')) {
            handlePay();
        }else {
            var msg = null;
            if(!vm.count) {
                msg = '请选择金额';
            }else if(!vm.pay) {
                msg = '请选择支付方式';
            }
            msg && fnToast(msg);
        }
    }

    // 支付订单，充值余额
    function handlePay() {
        // if(isPay) return;
        isPay = true;
        var params = {
            orderNo: '',
            payMethod: vm.pay,
            payType: '1',
            productId: '',
            payMoney: vm.count
        };
        if(vm.pay == 3) {
            params.productId = vm.moneyList[vm.active].productId;
        }
        var callback = function(data) {
            retUrl = data.retUrl;
            orderNo = data.orderNo;
            if(params.payMethod == 3) {
                fnApplePay(retUrl, orderNo);
            }else if(params.payMethod == 1) {
                // 微信
                fnwxPayPlus(retUrl);
            }else if(params.payMethod == 2) {
                // 支付宝
                fnaliPayPlus(retUrl);
            }
        };
        POST('payOrder/pay', params, callback);
    }

    // 支付回调
    function fnopenAudit(result) {
        //1成功 0失败 -1某些情况下支付失败
        if (result != -1) {
            fnOpenPublicWin('支付结果', 'video/pay_end',{
                retUrl: retUrl,
                from: pageParam.from,
                result: result,
                orderNo: orderNo,
                payMoney: vm.count,
                payMethod: vm.systemType == 'ios' ? '3' : vm.pay,
                refreshWin: pageParam.winName,
                refreshFrm: pageParam.frameName
            });
        }
        if(result == 1) {
            api.execScript({
                name: pageParam.winName,
                frameName: pageParam.frameName,
                script: 'paySuccessCallback('+vm.count+')'
            });
        }
    }
</script>

</html>